import { query } from '../db'

export interface Config {
  id: number
  key: string
  value: string
  type: string
  remark: string
  created_at: string
  updated_at: string
}

// 获取所有配置
export async function getAllConfigs(): Promise<Config[]> {
  const sql = 'SELECT * FROM blog_configs'
  const configs = await query(sql) as any[]
  return configs
}

// 根据键获取配置值
export async function getConfigByKey(key: string): Promise<Config | null> {
  const sql = 'SELECT * FROM blog_configs WHERE `key` = ?'
  const configs = await query(sql, [key]) as any[]
  return configs.length > 0 ? configs[0] : null
}

